# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=gtk2

pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.24.23
pkgrel=1
pkgdesc="GTK+ is a multi-platform toolkit (v2) (mingw-w64)"
arch=('any')
url="http://www.gtk.org"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
    "${MINGW_PACKAGE_PREFIX}-gobject-introspection"
    "${MINGW_PACKAGE_PREFIX}-pkg-config"
    "${MINGW_PACKAGE_PREFIX}-gtk-doc"
    "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
depends=(
    "${MINGW_PACKAGE_PREFIX}-gcc-libs"
    "${MINGW_PACKAGE_PREFIX}-atk>=1.29.2"
    "${MINGW_PACKAGE_PREFIX}-pango>=1.20"
    "${MINGW_PACKAGE_PREFIX}-glib2>=2.28.0"
    "${MINGW_PACKAGE_PREFIX}-cairo>=1.6"
    "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2>=2.21.0"
    "${MINGW_PACKAGE_PREFIX}-shared-mime-info")
optdepends=("${MINGW_PACKAGE_PREFIX}-gnome-icon-theme: Default icon theme")
install=gtk2-${CARCH}.install
options=(!libtool strip staticlibs)
source=("http://ftp.gnome.org/pub/gnome/sources/gtk+/${pkgver%.*}/gtk+-${pkgver}.tar.xz"
    'gtkrc'
    0001-fix-m4-location.mingw.patch
    0002-Fix-def-installation.all.patch
    0003-Fix-notebook-tab-state-change.mingw.patch
    0005-Fix-header-ref.all.patch
    0006-Fix-unix-symbols-in-docs.mingw.patch
    0009-give-cc-to-gir-scanner.mingw.patch
    0010-put-gtk-dll-into-path.mingw.patch
    0011-gir-for-gdkwin32.mingw.patch
    0012-embed-manifest.all.patch)

md5sums=('0be39fbed4ca125645175cd6e22f2548'
         '5105b21ea13dbfbef8975138b4355e7a'
         '4f4a6df623209e301b77a0e486f8c43d'
         '6a40366ed05024e1e93dbb9788c6747e'
         '09ea3e7b1642781441c050a1f6eb313d'
         'a6404599390c12b465a2e473535c94f5'
         '8a292c79c3e36a98a73108b840f4fecf'
         'e8bd83e4eb9877d009ad57458cf5a6b0'
         '9e0296da2986be7697cf343563b85d1f'
         '91d12fc6da9026deb0f94f38ab22a3ec'
         '864a719c5fea860ced90cacab5545b1d')

prepare() {
  cd gtk+-$pkgver
  patch -p1 -i ${srcdir}/0001-fix-m4-location.mingw.patch
  patch -p1 -i ${srcdir}/0002-Fix-def-installation.all.patch
  patch -p1 -i ${srcdir}/0003-Fix-notebook-tab-state-change.mingw.patch
  patch -p1 -i ${srcdir}/0005-Fix-header-ref.all.patch
  patch -p1 -i ${srcdir}/0006-Fix-unix-symbols-in-docs.mingw.patch
  patch -p1 -i ${srcdir}/0009-give-cc-to-gir-scanner.mingw.patch
  patch -p1 -i ${srcdir}/0010-put-gtk-dll-into-path.mingw.patch
  patch -p1 -i ${srcdir}/0011-gir-for-gdkwin32.mingw.patch
  patch -p1 -i ${srcdir}/0012-embed-manifest.all.patch
  
  autoreconf -fi
}

build() {
  cd "${srcdir}/gtk+-${pkgver}"
  CFLAGS+=" -mms-bitfields"
  CXXFLAGS+=" -mms-bitfields"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  rm "${srcdir}/gtk+-${pkgver}/gtk/gtk.def"
  ../gtk+-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --with-gdktarget=win32 \
    --disable-modules \
    --disable-cups \
    --disable-papi \
    --enable-static \
    --enable-shared \
    --enable-introspection \
    --disable-glibtest
  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="$pkgdir" install
  install -Dm644 "$srcdir/gtkrc" "${pkgdir}${MINGW_PREFIX}/share/gtk-2.0/gtkrc.example"
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm
}
